package com.itheima.test3;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class ServiceTest {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(8888);
        DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
        socket.receive(packet);
        System.out.println(new String(packet.getData(),0,packet.getLength()));
        //socket.close();

        //DatagramSocket socket1 = new DatagramSocket(9000);
        String s="我做的对吗？";
        byte[] bytes = s.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        DatagramPacket otherPacket = new DatagramPacket(bytes,bytes.length,address,9999);
        socket.send(otherPacket);
        socket.close();
    }
}
